package xyz.zhzby.cyzx.oj.messenger;

import io.swagger.annotations.ApiModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author zby
 * @date 2022/02/05
 */
@Component
@Slf4j
@ApiModel("消息发送服务. 用于发送新的评测任务至消息队列")
public class MessageSender {

    @Autowired
    private JmsTemplate jmsTemplate;

    /**
     * @Param [mapMessage] [Key-Value格式的消息]
     * @Return void []
     * @Author zby
     * @Date 2022/02/05
     * @Description 发送消息至消息队列.
     */
    public void sendMessage(final Map<String, Object> mapMessage) {
        String event = (String) mapMessage.get("event");

        jmsTemplate.convertAndSend(mapMessage);
        log.info(String.format("Submission task #%s has been created.", event));
    }

}
